<template v-loading="pageData.loadingUp2">
  <pageTabelLayout>
    <template #pageHeader>
      <div class="search-form isheader" v-if="headerShow">
        <div>
          <a-form v-if="tabsKeys == 1" size="small" :model="pageData" layout="inline">
            <a-form-item label="单号">
              <a-input
                allow-clear
                :style="{ width: '200px' }"
                class="bacClass"
                v-model="pageData.g"
              />
            </a-form-item>
            <CorporateSectorCascader
              :configCascader="configCascader2"
              @changeCascader="changeCascader2"
            />
            <a-form-item label="仓库">
              <a-select
                class="bacClass"
                :style="{ width: '200px' }"
                v-model="pageData.b"
                allow-clear
              >
                <a-option v-for="item in fhWhList" :value="item.id">
                  {{ item.warehouseName }}
                </a-option>
              </a-select>
            </a-form-item>
            <a-form-item label="日期">
              <a-range-picker
                :style="{ width: '240px' }"
                class="bacClass"
                @clear="onClear"
                allow-clear
                v-model="pageData.dropDownTime"
              />
            </a-form-item>
          </a-form>
          <a-form v-else-if="tabsKeys == 2" size="small" :model="pageData" layout="inline">
            <a-form-item label="采购单号">
              <a-input
                allow-clear
                :style="{ width: '200px' }"
                class="bacClass"
                v-model="pageData.h"
              />
            </a-form-item>
            <CorporateSectorCascader
              :configCascader="configCascader"
              @changeCascader="changeCascader"
            />
            <a-form-item label="物料编号">
              <a-input
                allow-clear
                :style="{ width: '200px' }"
                class="bacClass"
                v-model="pageData.d"
              />
            </a-form-item>
            <a-form-item label="物料名称">
              <a-input
                allow-clear
                :style="{ width: '200px' }"
                class="bacClass"
                v-model="pageData.e"
              />
            </a-form-item>
          </a-form>
          <a-form
            v-else-if="tabsKeys == 3 || tabsKeys == 4"
            size="small"
            :model="pageData"
            layout="inline"
          >
            <a-form-item label="调拨单号">
              <a-input
                allow-clear
                :style="{ width: '200px' }"
                class="bacClass"
                v-model="pageData.f"
              />
            </a-form-item>
            <a-form-item label="日期">
              <a-range-picker
                class="bacClass"
                :style="{ width: '240px' }"
                @clear="onClear1"
                allow-clear
                v-model="pageData.dropDownTime1"
              />
            </a-form-item>
          </a-form>
        </div>
      </div>
      <div class="my-divisders">
        <a-divider orientation="center">
          <icon-double-up
            v-if="headerShow"
            @click="headerShow = false"
            :strokeWidth="2"
            :size="18"
          />
          <icon-double-down v-else @click="headerShow = true" :strokeWidth="2" :size="18" />
        </a-divider>
      </div>

      <div>
        <div style="text-align: end">
          <Toolbar
            :items="toolbarList"
            @select="selectHandler"
            @rejected="rejecteds"
            @reders="redersOut"
            @del="delSles"
            @audit="audits"
            @complete="completes"
            @print="printInStock"
            @import="importShow"
            @excel="downloadHandler"
          >
          </Toolbar>
        </div>
      </div>

      <div class="gang"></div>
    </template>
    <template #pageTabel>
      <a-tabs
        :lazy-load="true"
        :justify="true"
        :default-active-key="tabsKeys"
        @change="tabsChanges"
      >
        <a-tab-pane title="已处理" :key="1">
          <AgGridVuesCopys
            :rowHeight="33"
            :headerHeight="33"
            :suppressRowClickSelection="true"
            :suppressCopyRowsToClipboard="true"
            :suppressDragLeaveHidesColumns="true"
            rowSelection="multiple"
            @grid-ready="gridReady"
            style="height: calc(100% - 45px)"
            @columnResized="onColumnResized"
            @columnMoved="onColumnMoved"
            @columnVisible="onColumnVisible"
            :defaultColDef="defaultColDef"
            class="ag-theme-alpine"
            :rowData="tableDataList"
            :columnDefs="tc"
            :localeText="localeText1"
          ></AgGridVuesCopys>
          <paginationCopys
            :page-size-options="pagingList1"
            :total="fySelet2.total"
            show-total
            show-jumper
            show-page-size
            @change="PageSize2"
            @page-size-change="change2"
            style="justify-content: center"
            :page-size="fySelet2.size"
            :current="fySelet2.page"
          />
        </a-tab-pane>
        <a-tab-pane title="采购单待处理" :key="2">
          <AgGridVuesCopys
            :rowHeight="33"
            :headerHeight="33"
            :suppressRowClickSelection="true"
            :suppressCopyRowsToClipboard="true"
            :suppressDragLeaveHidesColumns="true"
            rowSelection="multiple"
            @grid-ready="gridReady2"
            @columnResized="onColumnResized2"
            @columnMoved="onColumnMoved2"
            @columnVisible="onColumnVisible2"
            style="height: calc(100% - 45px)"
            :defaultColDef="defaultColDef2"
            class="ag-theme-alpine"
            :rowData="tableDataList2"
            :columnDefs="tc2"
            :localeText="localeText1"
          >
          </AgGridVuesCopys>
          <paginationCopys
            :page-size-options="pagingList1"
            :total="fySelet.total"
            show-total
            show-jumper
            show-page-size
            @change="PageSize"
            @page-size-change="change"
            style="justify-content: center"
            :page-size="fySelet.size"
            :current="fySelet.page"
          />
        </a-tab-pane>
        <a-tab-pane title="五金调拨单待处理" :key="3">
          <AgGridVuesCopys
            :rowHeight="33"
            :headerHeight="33"
            :suppressRowClickSelection="true"
            :suppressCopyRowsToClipboard="true"
            :suppressDragLeaveHidesColumns="true"
            rowSelection="multiple"
            @grid-ready="gridReady3"
            @columnResized="onColumnResized3"
            @columnMoved="onColumnMoved3"
            @columnVisible="onColumnVisible3"
            style="height: calc(100% - 45px)"
            :defaultColDef="defaultColDef3"
            class="ag-theme-alpine"
            :rowData="tableDataList3"
            :columnDefs="tc3"
            :localeText="localeText1"
          >
          </AgGridVuesCopys>
          <!-- <paginationCopys :page-size-options="pagingList1" :total="fySelet4.total" show-total show-jumper show-page-size
          @change="PageSize4" @page-size-change="change4" style="justify-content: center;" :page-size="fySelet4.size"
          :current="fySelet4.page" /> -->

          <paginationCopys
            :page-size-options="pagingList1"
            :total="fySelet3.total"
            show-total
            show-jumper
            show-page-size
            @change="PageSize3"
            @page-size-change="change3"
            style="justify-content: center"
            :page-size="fySelet3.size"
            :current="fySelet3.page"
          />
        </a-tab-pane>
        <a-tab-pane title="制具调拨单待处理" :key="4">
          <AgGridVuesCopys
            :rowHeight="33"
            :headerHeight="33"
            :suppressRowClickSelection="true"
            :suppressCopyRowsToClipboard="true"
            :suppressDragLeaveHidesColumns="true"
            rowSelection="multiple"
            @grid-ready="gridReady4"
            @columnResized="onColumnResized4"
            @columnMoved="onColumnMoved4"
            @columnVisible="onColumnVisible4"
            style="height: calc(100% - 45px)"
            :defaultColDef="defaultColDef4"
            class="ag-theme-alpine"
            :rowData="tableDataList4"
            :columnDefs="tc3"
            :localeText="localeText1"
          >
          </AgGridVuesCopys>
          <paginationCopys
            :page-size-options="pagingList1"
            :total="fySelet4.total"
            show-total
            show-jumper
            show-page-size
            @change="PageSize4"
            @page-size-change="change4"
            style="justify-content: center"
            :page-size="fySelet4.size"
            :current="fySelet4.page"
          />
        </a-tab-pane>
      </a-tabs>
    </template>
    <a-modal
      v-model:visible="cgOut.visible"
      :on-before-ok="cgHandleOk"
      @cancel="cadelvs"
      fullscreen
      :mask-closable="false"
    >
      <template #title>
        {{ cgOut.title }}
      </template>
      <div v-if="tabsKeys == 2" style="height: 100%">
        <span>入库仓库: </span>
        <a-input
          :style="{ width: '200px', marginBottom: '10px' }"
          disabled
          class="bacClass"
          v-model="cgRoutList[0].warehouseName"
        />
        <!-- <a-select
          :style="{ width: '200px', marginBottom: '10px' }"
          @change="warehouseChange"
          class="bacClass"
          disabled
          v-model="cgRoutList[0].warehouseName"
          allow-clear
          allow-search
        >
          <a-option v-for="item in cgRoutList" :value="item.id + '-' + item.warehouseName">{{
            item.warehouseName
          }}</a-option>
        </a-select> -->

        <div style="height: 100%; margin-bottom: -5px">
          <encapsulation-agrid
            ref="gridOptionRef2"
            :configaggrid="configaggrid2"
          ></encapsulation-agrid>
        </div>
      </div>
      <!-- <a-table
      v-else-if="tabsKeys == 3 || tabsKeys == 4"
      :columns="cgColumns2"
      :data="cgData2"
      :pagination="false"
      :bordered="{ cell: true }"
    >
      <template #grade="{ record }">
        <a-select
          @click="gradeChange"
          class="bacClass"
          v-model="record.grade"
          allow-clear
          allow-search
        >
          <a-option v-for="item in gradrList">{{ item.detailName }}</a-option>
        </a-select>
      </template>
    </a-table> -->
      <div style="width: 100%; height: 100%; margin-bottom: -5px" v-else-if="tabsKeys == 3">
        <encapsulation-agrid
          ref="gridOptionRef3"
          :configaggrid="configaggrid3"
          style="height: 100%"
        ></encapsulation-agrid>
      </div>
      <div style="width: 100%; height: 100%; margin-bottom: -5px" v-else-if="tabsKeys == 4">
        <encapsulation-agrid ref="gridOptionRef" :configaggrid="configaggrid"></encapsulation-agrid>
      </div>
    </a-modal>
    <a-drawer
      ok-text="导入excel"
      cancel-text="关闭"
      :drawer-style="{ zIndex: 9999 }"
      :width="400"
      :visible="pageData.showAdd"
      unmountOnClose
      @ok="importHandler"
      @cancel="pageData.showAdd = false"
    >
      <template #title> 导入Excel </template>
      <div v-loading="pageData.loadingUp2">
        <a-form ref="formRef" layout="horizontal" :model="dataForm">
          <CorporateSectorCascader
            :configCascader="configCascader3"
            @changeCascader="changeCascader3"
          />
          <a-form-item label="仓库" label-col-flex="80px">
            <a-select
              class="bacClass"
              style="width: 300px"
              v-model="dataForm.id"
              allow-clear
              size="small"
            >
              <a-option v-for="(item, index) in fhWhList1" :value="item.id" :key="index">
                {{ item.warehouseName }}
              </a-option>
            </a-select>
          </a-form-item>
        </a-form>
      </div>
    </a-drawer>
  </pageTabelLayout>
</template>
<script setup lang="ts">
  import { ref, reactive } from 'vue'
  import { post, get } from '@/api/http'
  import { localeText } from '@/api/aggridZw'

  import Toolbar from '@/components/Toolbar.vue'
  import printJS from 'print-js'
  import { Message, Modal } from '@arco-design/web-vue'
  import CorporateSectorCascader from '@/components/corporateSectorCascader/inde.vue'
  import WHService from '@/service/wh'
  import usePermission from '@/store/modules/permission'
  import { pagingList } from '@/api/paging'
  import { ElMessage, ElMessageBox } from 'element-plus'
  import filedownload from 'js-file-download'
  import dayjs from 'dayjs'
  import { saveOrUpdateGridState as saveOrUpdateGridState01 } from '@/hooks/useGridState'
  import { saveOrUpdateGridState as saveOrUpdateGridState02 } from '@/hooks/useGridState'
  import { saveOrUpdateGridState as saveOrUpdateGridState03 } from '@/hooks/useGridState'
  import { saveOrUpdateGridState as saveOrUpdateGridState04 } from '@/hooks/useGridState'
  import setTableTotalRow from '@/utils/setTableTotalRow.ts'
  const pagingList1: any = ref(pagingList)
  const permissionStore = usePermission()
  const gridOptionRef: any = ref(null)
  const tableColumns = ref([
    {
      headerName: '调拨单号',
      field: 'orderNo',
      width: 150,
    },
    {
      headerName: '出库类型',
      field: 'outStockType',
      width: 150,
    },
    {
      headerName: '发货公司',
      field: 'companyName',
      width: 150,
    },
    {
      headerName: '仓库类型',
      field: 'warehouseTypeName',
      width: 150,
    },
    {
      headerName: '仓库名称',
      field: 'warehouseName',
      width: 150,
    },
    {
      headerName: '入库仓库类型',
      field: 'inWarhouseTypeName',
      width: 150,
    },
    {
      headerName: '入库公司',
      field: 'inCompanyNAme',
      width: 150,
    },
    {
      headerName: '入库仓库名称',
      field: 'inWarehouseName',
      width: 150,
    },
    {
      headerName: '物料大类',
      field: 'majorCategory',
      width: 150,
    },
    {
      headerName: '物料中类',
      field: 'middleCategory',
      width: 150,
    },
    {
      headerName: '物料小类',
      field: 'subCategory',
      width: 150,
    },
    {
      headerName: '物料编号',
      field: 'materialCode',
      width: 150,
    },
    {
      headerName: '物料名称',
      field: 'materialName',
      width: 150,
    },
    {
      headerName: '规格',
      field: 'specification',
      width: 150,
    },
    {
      headerName: '数量',
      field: 'totalNum',
      width: 150,
    },
    {
      headerName: '单位',
      field: 'unit',
      width: 150,
    },
    {
      headerName: '等级',
      field: 'grade',
      width: 150,
      cellRenderer: {
        template: `
      <a-select
          @click="gradeChange1"
          class="bacClass"
          v-model="record.grade"
          allow-clear
          allow-search
        >
          <a-option v-for="item in gradrList" :value="item.detailName" >{{ item.detailName }}</a-option>
        </a-select>
            `,
        setup(props: any) {
          const record = ref(props.params.data)
          const gradeChange1 = (a: any, b: any) => {
            gradeChange()
          }
          return {
            record,
            gradeChange1,
            gradrList,
          }
        },
      },
    },
    {
      headerName: '发货时间',
      field: 'updateTime',
      width: 250,
    },
  ])
  let configaggrid = ref({
    url: '', //接口路径
    queryData: {
      //接口参数
    },
    paginationShow: false, //分页是否显示
    invokeiIterface: false, //是否调用接
    rowMultiSelectWithClick: true, //点击行是否多选
    column: tableColumns,
    fileName: 'ToolingTransferOrderToBeProcessed',
  })
  const gridOptionRef2: any = ref(null)
  const tableColumns2: any = [
    {
      headerName: '采购单号',
      field: 'purchaseOrderNo',
      width: 150,
    },
    {
      headerName: '采购公司',
      field: 'outCompanyName',
      width: 150,
    },
    {
      headerName: '供应商',
      field: 'supplierName',
      width: 150,
    },
    {
      headerName: '采购员',
      field: 'buyer',
      width: 150,
    },
    // {
    //   dataIndex: 'clientName',
    //   key: 'clientName',
    //   title: '客户名称',
    //   width: 150,
    // },
    {
      headerName: '物料名称',
      field: 'materialName',
      width: 150,
    },
    {
      headerName: '物料大类',
      field: 'majorCategory',
      width: 150,
    },
    {
      headerName: '物料中类',
      field: 'middleCategory',
      width: 150,
    },
    {
      headerName: '物料小类',
      field: 'subCategory',
      width: 150,
    },
    {
      headerName: '物料编号',
      field: 'materialCode',
      width: 150,
    },
    {
      headerName: '规格',
      field: 'specification',
      width: 150,
    },
    {
      headerName: '品牌',
      field: 'brandName',
      width: 150,
    },
    {
      headerName: '单位',
      field: 'unit',
      width: 150,
    },
    {
      headerName: '未入库数量',
      field: 'notInStockNum',
      width: 150,
    },
    {
      headerName: '不含税单价',
      field: 'price',
      width: 150,
      slotName: 'price',
    },
    {
      headerName: '不含税金额',
      field: 'amount',
      width: 150,
    },
    {
      headerName: '含税单价',
      field: 'taxPrice',
      width: 150,
    },
    {
      headerName: '含税金额',
      field: 'taxTotalPrice',
      width: 150,
    },
    {
      headerName: '等级',
      field: 'grade',
      slotName: 'grade',
      fixed: 'right',
      width: 150,
      cellRenderer: {
        template: `
      <a-select
          @click="gradeChange2"
          class="bacClass"
          v-model="record.grade"
          allow-clear
          allow-search
        >
          <a-option v-for="item in gradrList" :value="item.detailName" >{{ item.detailName }}</a-option>
        </a-select>
            `,
        setup(props: any) {
          const record = ref(props.params.data)
          const gradeChange1 = (a: any, b: any) => {
            gradeChange()
          }
          return {
            record,
            gradeChange1,
            gradrList,
          }
        },
      },
    },
    {
      headerName: '已入库数量 ',
      field: 'inStockNum',
      fixed: 'right',
      width: 150,
    },
    {
      headerName: '采购入库数量',
      field: 'totalNum',
      fixed: 'right',
      slotName: 'totalNum',
      width: 150,
      cellRenderer: {
        template: `
        <a-input-number
          class="bacClass"
          v-model="record.totalNum"
          :min="0"
          :max="record.notInStockNum"
          :precision="2"
        ></a-input-number>
            `,
        setup(props: any) {
          const record = ref(props.params.data)
          return {
            record,
          }
        },
      },
    },
    {
      headerName: '入库仓库',
      field: 'warehouseName',
      fixed: 'right',
      slotName: 'warehouseName',
      width: 150,
    },
  ]
  let configaggrid2 = ref({
    url: '', //接口路径
    queryData: {
      //接口参数
    },
    paginationShow: false, //分页是否显示
    invokeiIterface: false, //是否调用接
    rowMultiSelectWithClick: true, //点击行是否多选
    column: tableColumns2,
    fileName: 'PurchaseOrderPending',
  })
  const gridOptionRef3: any = ref(null)
  const tableColumns3: any = [
    {
      field: 'orderNo',
      headerName: '调拨单号',
      width: 150,
    },
    {
      field: 'outStockType',
      headerName: '出库类型',
      width: 150,
    },
    {
      field: 'companyName',
      headerName: '发货公司',
      width: 150,
    },
    {
      field: 'warehouseTypeName',
      headerName: '仓库类型',
      width: 150,
    },
    {
      field: 'warehouseName',
      headerName: '仓库名称',
      width: 150,
    },
    {
      field: 'inWarehouseTypeName',
      headerName: '入库仓库类型',
      width: 150,
    },
    {
      field: 'inCompanyName',
      headerName: '入库公司',
      width: 150,
    },
    {
      field: 'inWarehouseName',
      headerName: '入库仓库名称',
      width: 150,
    },
    {
      headerName: '物料大类',
      field: 'majorCategory',
      width: 150,
    },
    {
      headerName: '物料中类',
      field: 'middleCategory',
      width: 150,
    },
    {
      headerName: '物料小类',
      field: 'subCategory',
      width: 150,
    },
    {
      field: 'materialCode',
      headerName: '物料编号',
      width: 150,
    },
    {
      field: 'materialName',
      headerName: '物料名称',
      width: 150,
    },
    {
      field: 'specification',
      headerName: '规格',
      width: 150,
    },
    {
      field: 'totalNum',
      headerName: '数量',
      width: 150,
    },
    {
      field: 'unit',
      headerName: '单位',
      width: 150,
    },
    {
      field: 'grade',
      slotName: 'grade',
      headerName: '等级',
      fixed: 'right',
      width: 150,
      cellRenderer: {
        // <a-select
        //   @click="gradeChange"
        //   class="bacClass"
        //   v-model="record.grade"
        //   allow-clear
        //   allow-search
        // >
        //   <a-option v-for="item in gradrList">{{ item.detailName }}</a-option>
        // </a-select>
        template: `
        <a-select
          @click="callGradeChange"
          class="bacClass"
          v-model="record.grade"
          allow-clear
          allow-search
        >
          <a-option v-for="item in gradrList">{{ item.detailName }}</a-option>
        </a-select>
        `,
        setup(props: any) {
          const record = ref(props.params.data)
          const callGradeChange = () => {
            gradeChange()
          }
          return {
            record,
            callGradeChange,
            gradrList,
          }
        },
      },
    },
    {
      field: 'updateTime',
      headerName: '发货时间',
      width: 250,
    },
  ]
  let configaggrid3 = ref({
    url: '', //接口路径
    queryData: {
      //接口参数
    },
    paginationShow: false, //分页是否显示
    invokeiIterface: false, //是否调用接
    rowMultiSelectWithClick: true, //点击行是否多选
    column: tableColumns3,
    fileName: 'PurchaseOrderPending',
  })
  const toolbarList: any = ref([
    `${permissionStore.hasPermisson('wjcrk.yclcx') ? '查询' : ''}`,
    `${permissionStore.hasPermisson('wjcrk.sh') ? '审核' : ''}`,
    // `${permissionStore.hasPermisson('wjcrk.sc') ? '删除' : ''}`,
    `${permissionStore.hasPermisson('wjcrk.dr') ? '导入' : ''}`,
    // `${permissionStore.hasPermisson('wjcrk.mbxz') ? '模板下载' : ''}`,
    '打印',
  ])

  const fySelet: any = reactive({
    total: 1,
    size: 10,
    page: 1,
  })

  const PageSize = (val: any) => {
    fySelet.page = val
    cxCgsList()
  }

  const change = (val: any) => {
    fySelet.size = val
    cxCgsList()
  }

  const fySelet2: any = reactive({
    total: 1,
    size: 10,
    page: 1,
  })

  const PageSize2 = (val: any) => {
    fySelet2.page = val
    cxYcList()
  }

  const change2 = (val: any) => {
    fySelet2.size = val
    cxYcList()
  }

  const fySelet3: any = reactive({
    total: 1,
    size: 10,
    page: 1,
  })

  const PageSize3 = (val: any) => {
    fySelet3.page = val
    cxDbsList()
  }

  const change3 = (val: any) => {
    fySelet3.size = val
    cxDbsList()
  }

  const fySelet4: any = reactive({
    total: 1,
    size: 10,
    page: 1,
  })

  const PageSize4 = (val: any) => {
    fySelet4.page = val
    cxDbsList()
  }

  const change4 = (val: any) => {
    fySelet4.size = val
    cxDbsList()
  }
  const pageData: any = reactive({
    a: '',
    b: '',
    c: '',
    d: '',
    e: '',
    f: '',
    g: '',
    h: '',
    dropDownTime: [dayjs().format('YYYY-MM-DD'), dayjs().format('YYYY-MM-DD')],
    dropDownTime1: [dayjs().format('YYYY-MM-DD'), dayjs().format('YYYY-MM-DD')],
    showAdd: false,
    loadingUp2: false,
  })
  const dataForm = reactive<any>({
    id: '',
  })
  const headerShow = ref(true)
  const importShow = () => {
    dataForm.id = ''
    pageData.showAdd = true
  }
  //模板下载
  const downloadHandler = async () => {
    try {
      pageData.loadingUp2 = true
      let res: any = await get({
        url: 'wms/ironwareInStock/uploadModel',
        responseType: 'blob',
        headers: {
          token: sessionStorage.getItem('USER-TOKEN-KEY'),
        },
      })
      // if (res.code == 200) {
      console.log(res)
      filedownload(res, '固定资产导入模板.xlsx')
      pageData.loadingUp2 = false
      // return
      // }
      // ElMessage.error(res.message)
    } finally {
      pageData.loadingUp2 = false
    }
  }
  //导入
  const importHandler = () => {
    if (!dataForm.id) {
      ElMessage.warning('请选择仓库')
      return
    }
    const inputEle: HTMLInputElement = document.createElement('input')
    inputEle.type = 'file'
    inputEle.id = 'fileUploadExcel'
    inputEle.accept =
      'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel'
    inputEle.addEventListener('change', async (e) => {
      const formData = new FormData()
      if (inputEle.files !== null) {
        formData.append('file', inputEle.files[0] || '')
        formData.append('warehouseId', dataForm.id)
      } else {
        ElMessage.warning('未选择文件！')
        return
      }
      // console.log(formData.values())
      try {
        pageData.loadingUp2 = true
        let res: any = await post({
          url: 'wms/ironwareInStock/importInStockByExcel',
          data: formData,
          headers: {
            'Content-Type': 'multipart/form-data',
            token: sessionStorage.getItem('USER-TOKEN-KEY'),
          },
        })
        if (res.code == 200) {
          ElMessage.success('导入成功')
          pageData.showAdd = false
          cxYcList()
          pageData.loadingUp2 = false
          return
        }
        ElMessage.error(res.message)
      } finally {
        pageData.loadingUp2 = false
      }
    })
    inputEle.click()
  }
  const tableDataList = ref([])
  const tableDataList2: any = ref([])
  const tableDataList3 = ref([])
  const tableDataList4 = ref([])
  const gridOption = ref()
  const colState = ref()
  const gridReady = (params: any) => {
    gridOption.value = params.api
    colState.value = params.columnApi
  }
  let oneDayTime: any = ref([dayjs().format('YYYY-MM-DD'), dayjs().format('YYYY-MM-DD')])
  const gridOption2 = ref()
  const colState2 = ref()
  const gridReady2 = (params: any) => {
    gridOption2.value = params.api
    colState2.value = params.columnApi
  }

  const gridOption3 = ref()
  const colState3 = ref()
  const gridReady3 = (params: any) => {
    gridOption3.value = params.api
    colState3.value = params.columnApi
  }
  const gridOption4 = ref()
  const colState4 = ref()
  const gridReady4 = (params: any) => {
    gridOption4.value = params.api
    colState4.value = params.columnApi
  }

  const defaultColDef = {
    sortable: true,
    resizable: true,
    filter: true,
  }

  const defaultColDef2 = {
    sortable: true,
    resizable: true,
    filter: true,
  }

  const defaultColDef3 = {
    sortable: true,
    resizable: true,
    filter: true,
  }
  const defaultColDef4 = {
    sortable: true,
    resizable: true,
    filter: true,
  }
  const localeText1: any = ref(localeText)

  const tc = [
    {
      showRowGroup: 'hide_def',
      headerName: '',
      checkboxSelection: true,
      headerCheckboxSelection: true,
      pinned: 'left',
      width: 50,
      resizable: false,
      filter: false,
      sortable: false,
      minWidth: 50,
      maxWidth: 50,
      lockPosition: 'left',
    },
    {
      headerName: '单号',
      field: 'orderNo',
      // pinned: o['fixed'],
      width: 150,
      filter: 'agSetColumnFilter',
    },
    {
      headerName: '入库类型',
      field: 'inStockType',
      width: 150,
    },
    {
      headerName: '公司',
      field: 'companyName',
      width: 150,
    },
    {
      headerName: '仓库类型',
      field: 'warehouseTypeName',
      width: 150,
    },
    {
      headerName: '仓库名称',
      field: 'warehouseName',
      width: 150,
    },
    {
      headerName: '采购单号',
      field: 'purchaseOrderNo',
      width: 150,
    },
    {
      headerName: '供应商名称',
      field: 'supplierName',
      width: 150,
    },
    // {
    //   headerName: '客户名称',
    //   field: 'customerName',
    //   width: 150,
    // },
    {
      headerName: '物料大类',
      field: 'majorCategory',
      width: 150,
    },
    {
      headerName: '物料中类',
      field: 'middleCategory',
      width: 150,
    },
    {
      headerName: '物料小类',
      field: 'subCategory',
      width: 150,
    },
    {
      headerName: '物料编号',
      field: 'materialCode',
      width: 150,
    },
    {
      headerName: '物料名称',
      field: 'materialName',
      width: 150,
    },
    {
      headerName: '规格',
      field: 'specification',
      width: 150,
    },
    {
      headerName: '总数',
      field: 'totalNum',
      width: 150,
    },
    {
      headerName: '单位',
      field: 'unit',
      width: 150,
    },
    {
      headerName: '品牌',
      field: 'brandName',
      width: 150,
    },
    {
      headerName: '等级',
      field: 'grade',
      width: 150,
    },
    {
      headerName: '合同号',
      field: 'orderNo',
      width: 150,
    },
    {
      headerName: 'OA付款/报销单号',
      field: 'oaCode',
      width: 150,
    },
    {
      headerName: '是否开票',
      field: 'invoicState',
      width: 150,
    },
    {
      headerName: '布笼',
      field: 'location',
      width: 150,
    },
    {
      headerName: '位置号',
      field: 'locationMark',
      width: 150,
    },
    {
      headerName: '区域',
      field: 'district',
      width: 150,
    },
    {
      headerName: '创建人',
      field: 'createName',
      width: 150,
    },
    {
      headerName: '创建时间',
      field: 'createTime',
      width: 150,
    },
    {
      headerName: '修改人',
      field: 'updateName',
      width: 150,
    },
    {
      headerName: '修改时间',
      field: 'updateTime',
      width: 150,
    },
    {
      headerName: '打印状态',
      field: 'printState',
      pinned: 'right',
      width: 150,
      cellRenderer: {
        template: `
            <a-button v-if="states == 1" status="success">已打印</a-button>
            <a-button v-else="states == 0" type="dashed" status="warning">未打印</a-button>
            `,
        setup(props: any) {
          return {
            states: props.params.data.printState,
          }
        },
      },
      cellStyle: (params: any) => {
        if (params.node.rowPinned == 'bottom') return { display: 'none' }
      },
      filterParams: {
        valueFormatter: function (params: any) {
          return params.value == '0' ? '未打印' : params.value == '1' ? '已打印' : ''
        },
      },
    },
    {
      headerName: '状态',
      field: 'infoState',
      pinned: 'right',
      width: 150,
      cellRenderer: {
        template: `
            <a-button v-if="states == 2" status="success">已入库</a-button>
            <a-button v-else="states == 0" type="dashed" status="success">待审核</a-button>
            `,
        setup(props: any) {
          return {
            states: props.params.data.infoState,
          }
        },
      },
      cellStyle: (params: any) => {
        if (params.node.rowPinned == 'bottom') return { display: 'none' }
      },
      filterParams: {
        valueFormatter: function (params: any) {
          return params.value == '0' ? '待审核' : params.value == '2' ? '已入库' : ''
        },
      },
    },
  ]

  const tc2 = [
    {
      showRowGroup: 'hide_def',
      headerName: '',
      checkboxSelection: true,
      headerCheckboxSelection: true,
      pinned: 'left',
      width: 50,
      resizable: false,
      filter: false,
      sortable: false,
      minWidth: 50,
      maxWidth: 50,
      lockPosition: 'left',
    },
    {
      headerName: '采购单号',
      field: 'purchaseOrderNo',
      // pinned: o['fixed'],
      width: 150,
    },
    {
      headerName: '采购公司',
      field: 'outCompanyName',
      // pinned: o['fixed'],
      width: 150,
    },
    {
      headerName: '主体',
      field: 'companyEntity',
      // pinned: o['fixed'],
      width: 150,
    },
    {
      headerName: '供应商',
      field: 'supplierName',
      width: 150,
    },
    {
      headerName: '采购员',
      field: 'buyer',
      width: 150,
    },
    // {
    //   headerName: '客户名称',
    //   field: 'clientName',
    //   width: 150,
    // },
    {
      headerName: '物料大类',
      field: 'majorCategory',
      width: 150,
    },
    {
      headerName: '物料中类',
      field: 'middleCategory',
      width: 150,
    },
    {
      headerName: '物料小类',
      field: 'subCategory',
      width: 150,
    },
    {
      headerName: '物料名称',
      field: 'materialName',
      width: 150,
    },
    {
      headerName: '物料编号',
      field: 'materialCode',
      width: 150,
    },
    {
      headerName: '规格',
      field: 'specification',
      width: 150,
    },
    {
      headerName: '品牌',
      field: 'brandName',
      width: 150,
    },
    {
      headerName: '单位',
      field: 'unit',
      width: 150,
    },
    {
      headerName: '位置号',
      field: 'locationMark',
      width: 150,
    },
    {
      headerName: '区域',
      field: 'district',
      width: 150,
    },
    {
      headerName: '等级',
      field: 'grade',
      width: 150,
    },
    {
      headerName: '以旧换新',
      field: 'oldNewService',
      width: 150,
      cellRenderer: {
        template: `<a-checkbox v-if="!isTotal" v-model="val" disabled></a-checkbox>
        <div v-else></div>
        `,
        setup(props: any) {
          let val = ref()
          val.value =
            props.params.data.oldNewService == null
              ? false
              : props.params.data.oldNewService == 1
              ? true
              : false
          const isTotal = ref(props.params.node.rowPinned == 'bottom')
          return {
            val,
            isTotal,
          }
        },
      },
    },
    {
      headerName: '采购数量',
      field: 'totalNum',
      width: 150,
    },
    {
      headerName: '采购单位',
      field: 'purchaseUnit',
      width: 150,
    },
    // {
    //     headerName: '换算数量',
    //     field: 'totalNum',
    //     width: 150
    // },
    // {
    //     headerName: '换算单位',
    //     field: 'unit',
    //     width: 150
    // },
    {
      headerName: '已入库数量',
      field: 'inStockNum',
      width: 150,
    },
    {
      headerName: '未入库数量',
      field: 'notInStockNum',
      width: 150,
    },
    {
      headerName: '不含税单价',
      field: 'price',
      width: 150,
      slotName: 'price',
    },
    {
      headerName: '不含税金额',
      field: 'amount',
      width: 150,
    },
    {
      headerName: '含税单价',
      field: 'taxPrice',
      width: 150,
    },
    {
      headerName: '含税金额',
      field: 'taxTotalPrice',
      width: 150,
    },
  ]

  const tc3 = [
    {
      showRowGroup: 'hide_def',
      headerName: '',
      checkboxSelection: true,
      headerCheckboxSelection: true,
      pinned: 'left',
      width: 50,
      resizable: false,
      filter: false,
      sortable: false,
      minWidth: 50,
      maxWidth: 50,
      lockPosition: 'left',
    },
    {
      headerName: '调拨单号',
      field: 'orderNo',
      // pinned: o['fixed'],
      width: 150,
    },
    {
      headerName: '出库类型',
      field: 'outStockType',
      // pinned: o['fixed'],
      width: 150,
    },
    {
      headerName: '发货公司',
      field: 'companyName',
      width: 150,
    },
    {
      headerName: '仓库类型',
      field: 'warehouseTypeName',
      width: 150,
    },
    {
      headerName: '仓库名称',
      field: 'warehouseName',
      width: 150,
    },
    {
      headerName: '入库仓库类型',
      field: 'inWarehouseTypeName',
      width: 150,
    },
    {
      headerName: '入库公司',
      field: 'inCompanyName',
      width: 150,
    },
    {
      headerName: '入库仓库名称',
      field: 'inWarehouseName',
      width: 150,
    },
    {
      headerName: '物料大类',
      field: 'majorCategory',
      width: 150,
    },
    {
      headerName: '物料中类',
      field: 'middleCategory',
      width: 150,
    },
    {
      headerName: '物料小类',
      field: 'subCategory',
      width: 150,
    },
    {
      headerName: '物料编号',
      field: 'materialCode',
      width: 150,
    },
    {
      headerName: '物料名称',
      field: 'materialName',
      width: 150,
    },
    {
      headerName: '规格',
      field: 'specification',
      width: 150,
    },
    {
      headerName: '等级',
      field: 'grade',
      width: 150,
    },
    {
      headerName: '位置号',
      field: 'locationMark',
      width: 150,
    },
    {
      headerName: '区域',
      field: 'district',
      width: 150,
    },
    {
      headerName: '数量',
      field: 'totalNum',
      width: 150,
    },
    {
      headerName: '单位',
      field: 'unit',
      width: 150,
    },
    {
      headerName: '发货时间',
      field: 'auditDate',
      width: 150,
    },
  ]
  onMounted(() => {
    updateGridState01()
    updateGridState02()
    updateGridState03()
    updateGridState04()
    cxYcList()
    gradeChange()
  })
  const selectHandler = () => {
    if (tabsKeys.value == 1) {
      fySelet2.page = 1
      cxYcList()
    } else if (tabsKeys.value == 2) {
      fySelet.page = 1
      cxCgsList()
    } else if (tabsKeys.value == 3) {
      fySelet3.page = 1
      cxDbsList()
    } else if (tabsKeys.value == 4) {
      fySelet4.page = 1
      cxDbsList()
    }
  }

  const tabsKeys = ref(1)
  const warehouseName = ref('')

  const tabsChanges = (e: any) => {
    console.log('eeeeeeeeeeeeeeee=>' + e)

    tabsKeys.value = e
    if (e == 1) {
      cxYcList()
      toolbarList.value = [
        `${permissionStore.hasPermisson('wjcrk.yclcx') ? '查询' : ''}`,
        `${permissionStore.hasPermisson('wjcrk.sh') ? '审核' : ''}`,
        // `${permissionStore.hasPermisson('wjcrk.sc') ? '删除' : ''}`,
        `${permissionStore.hasPermisson('wjcrk.dr') ? '导入' : ''}`,
        // `${permissionStore.hasPermisson('wjcrk.mbxz') ? '模板下载' : ''}`,
        '打印',
      ]
    } else if (e == 2) {
      console.log('2222222222222222222222222')

      cxCgsList()
      toolbarList.value = []
      toolbarList.value = [
        `${permissionStore.hasPermisson('wjcrk.cgddclcx') ? '查询' : ''}`,
        `${permissionStore.hasPermisson('wjcrk.cgddclrk') ? '入库' : ''}`,
        `${permissionStore.hasPermisson('wjcrk.wc') ? '完成' : ''}`,
      ]
    } else if (e == 3) {
      cxDbsList()

      toolbarList.value = [
        `${permissionStore.hasPermisson('wjcrk.dbddclcx') ? '查询' : ''}`,
        `${permissionStore.hasPermisson('wjcrk.dbddclrk') ? '入库' : ''}`,
        `${permissionStore.hasPermisson('wjcrk.bh') ? '驳回' : ''}`,
      ]
    } else if (e == 4) {
      cxDbsList()
      toolbarList.value = [
        `${permissionStore.hasPermisson('wjcrk.dbddclcx') ? '查询' : ''}`,
        `${permissionStore.hasPermisson('wjcrk.dbddclrk') ? '入库' : ''}`,
        `${permissionStore.hasPermisson('wjcrk.bh') ? '驳回' : ''}`,
      ]
    }
  }

  const cgDcuList = reactive({
    pwDds: '',
    pwDds2: '',
  })

  const cxCgsList = async () => {
    // isWlNameds,
    // isWlCodeds,
    post({
      url: 'purchase/PurchaseOrder/getPurchaseCode',
      data: {
        // purchaseCode: isCgds.value,
        companyId: pageData.c == '' ? null : pageData.c,
        page: fySelet.page,
        size: fySelet.size,
        purchaseCode: pageData.h,
        materialCode: pageData.d,
        materialName: pageData.e,
      },
    }).then((res: any) => {
      setTableTotalRow(gridOption2, res.data.data, [
        'totalNum',
        'inStockNum',
        'notInStockNum',
        'amount',
        'taxTotalPrice',
      ])
      gridOption2.value.setRowData(res.data.data)
      tableDataList2.value = res.data.data
      fySelet.total = res.data.total
    })
  }

  const cxDbsList = () => {
    if (pageData.dropDownTime1.length == 0) {
      var beginTime = ''
      var endTime = ''
    } else {
      var beginTime = pageData.dropDownTime1[0]
      var endTime = pageData.dropDownTime1[1]
    }
    if (tabsKeys.value == 3) {
      post({
        url: 'wms/ironwareInStock/getAllocatePage',
        data: {
          page: fySelet3.page,
          size: fySelet3.size,
          inWarehouseTypeName: '五金仓',
          orderNo: pageData.f,
          infoType: 2,
          infoState: 2,
          beginTime: compareDate(beginTime, endTime) == true ? endTime : beginTime,
          endTime: compareDate(beginTime, endTime) == true ? beginTime : endTime,
        },
      }).then((res: any) => {
        setTableTotalRow(gridOption3, res.data.data, ['totalNum'])
        gridOption3.value.setRowData(res.data.data)
        tableDataList3.value = res.data.data
        fySelet3.total = res.data.total
      })
    } else if (tabsKeys.value == 4) {
      post({
        url: 'wms/toolInStock/getAllocatePage',
        data: {
          page: fySelet4.page,
          size: fySelet4.size,
          inWarehouseTypeName: '五金仓',
          orderNo: pageData.f,
          infoType: 2,
          infoState: 2,
          beginTime: compareDate(beginTime, endTime) == true ? endTime : beginTime,
          endTime: compareDate(beginTime, endTime) == true ? beginTime : endTime,
        },
      }).then((res: any) => {
        setTableTotalRow(gridOption4, res.data.data, ['totalNum'])
        gridOption4.value.setRowData(res.data.data)
        tableDataList4.value = res.data.data
        fySelet4.total = res.data.total
      })
    }
  }

  const compareDate = (dateTime1: any, dateTime2: any) => {
    var formatDate1 = new Date(dateTime1)
    var formatDate2 = new Date(dateTime2)
    if (formatDate1 > formatDate2) {
      return true
    } else {
      return false
    }
  }
  // const setTableTotalRow = (instance: any, data: any, headArr: any) => {
  //   const totalRowObj = {
  //     defaultCkBox: '汇总',
  //   }
  //   headArr.forEach((item: any) => {
  //     totalRowObj[item] = data.reduce((sum: any, cur: any) => {
  //       if (!cur[item]) cur[item] = 0
  //       return Number(sum) + Number(cur[item])
  //     }, 0)
  //   })
  //   for (let key in totalRowObj) {
  //     if (key !== 'defaultCkBox') totalRowObj[key] = parseFloat(totalRowObj[key]).toFixed(2)
  //   }
  //   console.log('totalRowObj', totalRowObj)
  //   console.log('ref', instance.value)
  //   nextTick(() => {
  //     instance.value.setPinnedBottomRowData([totalRowObj])
  //   })
  // }
  const cxYcList = () => {
    if (pageData.dropDownTime.length == 0) {
      var beginTime = ''
      var endTime = ''
    } else {
      var beginTime = pageData.dropDownTime[0]
      var endTime = pageData.dropDownTime[1]
    }
    post({
      url: 'wms/ironwareInStock/getPage',
      data: {
        page: fySelet2.page,
        size: fySelet2.size,
        companyId: pageData.a,
        warehouseId: pageData.b,
        orderNo: pageData.g,
        beginTime: compareDate(beginTime, endTime) == true ? endTime : beginTime,
        endTime: compareDate(beginTime, endTime) == true ? beginTime : endTime,
      },
    }).then((res: any) => {
      setTableTotalRow(gridOption, res.data.data, ['totalNum'])
      gridOption.value.setRowData(res.data.data)
      tableDataList.value = res.data.data
      fySelet2.total = res.data.total
    })
  }

  const printInStock = () => {
    let ptDatas = gridOption.value.getSelectedRows()

    let orderNoList = ptDatas.map((o: any) => {
      return o.orderNo
    })
    let orderNoSet = Array.from(new Set(orderNoList))
    if (orderNoList.length == 0) {
      Message.error('请选择入库单')
      return
    }
    post({
      url: 'wms/ironwareInStock/printInStockInfo',
      data: orderNoSet,
      responseType: 'blob',
    }).then((res: any) => {
      let reader = new FileReader()
      reader.readAsDataURL(res)
      reader.onload = function () {
        let pdfBase64 = reader.result.replace('data:application/pdf;base64,', '')
        printJS({ printable: pdfBase64, type: 'pdf', base64: true })
      }
    })
  }

  const cgRoutList: any = ref([{ warehouseName: '' }])

  const redersOut = () => {
    if (tabsKeys.value == 2) {
      if (gridOption2.value.getSelectedRows().length == 0) {
        Message.error('请选择采购单')
        return
      }
      for (let i = 0; i < gridOption2.value.getSelectedRows().length; i++) {
        for (let j = i + 1; j < gridOption2.value.getSelectedRows().length; j++) {
          if (
            gridOption2.value.getSelectedRows()[i].purchaseOrderNo !=
            gridOption2.value.getSelectedRows()[j].purchaseOrderNo
          ) {
            Message.error('请勾选相同采购单入库')
            return
          }
        }
      }
      cgData.value = JSON.parse(JSON.stringify(gridOption2.value.getSelectedRows()))
      gridOptionRef2.value.setdataListIterface(cgData.value)
      cgData.value.forEach((e: any) => {
        e['totalNum'] = e['notInStockNum']
        e['noTaxMoney'] = e['price'] * e['totalNum']
      })

      post({
        url: 'wms/warehouse/getWarehouseByPara',
        data: {
          virtuallyState: 1,
        },
      }).then((res: any) => {
        if (res.code == 200) {
          cgRoutList.value = res.data
          warehouseName.value = res.data[0].warehouseName
          nextTick(() => {
            cgOut.title = '采购单入库'
            cgOut.visible = true
          })
        } else {
          Message.error(res.msg)
        }
      })
    } else if (tabsKeys.value == 3) {
      if (gridOption3.value.getSelectedRows().length == 0) {
        Message.error('请选择调拨单')
        return
      }
      for (let i = 0; i < gridOption3.value.getSelectedRows().length; i++) {
        for (let j = i + 1; j < gridOption3.value.getSelectedRows().length; j++) {
          if (
            gridOption3.value.getSelectedRows()[i].orderNo !=
            gridOption3.value.getSelectedRows()[j].orderNo
          ) {
            Message.error('请勾选相同调拨单入库')
            return
          }
        }
      }
      cgData2.value = JSON.parse(JSON.stringify(gridOption3.value.getSelectedRows()))
      gridOptionRef3.value.setdataListIterface(cgData2.value)
      //record.grade
      //cgData2.value.forEach((res:any)=>{
      //   if(!res['grade']){
      //      res.grade = 'A'
      //   }
      //})
      cgOut.title = '调拨单入库'
      cgOut.visible = true
    } else if (tabsKeys.value == 4) {
      if (gridOption4.value.getSelectedRows().length == 0) {
        Message.error('请选择调拨单')
        return
      }
      for (let i = 0; i < gridOption4.value.getSelectedRows().length; i++) {
        for (let j = i + 1; j < gridOption4.value.getSelectedRows().length; j++) {
          if (
            gridOption4.value.getSelectedRows()[i].orderNo !=
            gridOption4.value.getSelectedRows()[j].orderNo
          ) {
            Message.error('请勾选相同调拨单入库')
            return
          }
        }
      }
      cgData2.value = JSON.parse(JSON.stringify(gridOption4.value.getSelectedRows()))
      gridOptionRef.value.setdataListIterface(cgData2.value)
      cgOut.title = '调拨单入库'
      cgOut.visible = true
    }
  }

  const cgOut = reactive({
    visible: false,
    title: '采购单入库',
  })

  const cgHandleOk = async () => {
    if (tabsKeys.value == 2) {
      // for (let i = 0; i < cgData.value.length; i++) {
      //   if (
      //     cgData.value[i].warehouseName == '' ||
      //     cgData.value[i].warehouseName == undefined ||
      //     cgData.value[i].warehouseName == null
      //   ) {
      //     Message.error('请选择入库仓库')
      //     return false
      //   }
      // }

      try {
        const listData = JSON.parse(JSON.stringify(gridOptionRef2.value.getListData()))
       console.log(cgRoutList.value)
        // let xxxx: any = cgRoutList.value.filter((pop: any) => {
        //   return pop.warehouseName == warehouseNameAanId.value.split('-')[1]
        // })
      //  let findName =  cgRoutList.value.find(item =>item.warehouseName == listData[0].warehouseName)
        listData.forEach((res: any) => {
          res['infoType'] = 1
          res['inStockType'] = '采购入库'
          res['warehouseTypeName'] = '五金仓'
          res['companyId'] = cgRoutList.value[0].firmId
          res['companyName'] = cgRoutList.value[0].firm
          res['warehouseId'] = cgRoutList.value[0].id
          res['warehouseName']=cgRoutList.value[0].warehouseName
        })
        console.log(listData);
        const { code, message } = await post({
          url: 'wms/ironwareInStock/addStock',
          data: listData,
        })
        if (code == 200) {
          cxYcList()
          cxCgsList()
          // warehouseNameAanId.value = ''
          Message.success('成功')
          return true
        }
        Message.error(message)
        return false
      } catch (error) {
        console.error(error)
      }
    } else if (tabsKeys.value == 3) {
      // for (let i = 0; i < cgData2.value.length; i++) {
      // if (cgData2.value[i].grade == '' || cgData2.value[i].grade == undefined || cgData2.value[i].grade == null) {
      //     Message.error('请选择等级')
      //     return false
      // }
      // }
      cgData2.value.forEach((res: any) => {
        res['infoType'] = 2
        res['inStockType'] = '调拨入库'
        // res['warehouseTypeName'] = '五金仓'
        delete res.firmId
        delete res.firm
        delete res.id
      })
      const { code, message } = await post({
        url: 'wms/ironwareInStock/addStock',
        data: cgData2.value,
      })

      if (code == 200) {
        cxYcList()
        cxDbsList()
        Message.success('成功')
        return true
      }

      Message.error(message)
      return false
    } else if (tabsKeys.value == 4) {
      // for (let i = 0; i < cgData2.value.length; i++) {
      //     if (cgData2.value[i].grade == '' || cgData2.value[i].grade == undefined || cgData2.value[i].grade == null) {
      //         Message.error('请选择等级')
      //         return false
      //     }
      // }
      cgData2.value.forEach((res: any) => {
        res['infoType'] = 2
        res['inStockType'] = '调拨入库'
        // res['warehouseTypeName'] = '制具仓'
        delete res.firmId
        delete res.firm
        delete res.id
      })
      const { code, message } = await post({
        url: 'wms/ironwareInStock/addStock',
        data: cgData2.value,
      })

      if (code == 200) {
        cxYcList()
        cxDbsList()
        Message.success('成功')
        return true
      }

      Message.error(message)
      return false
    }
  }

  // const warehouseChange = ($event: any, record: any) => {
  //     if ($event != '' || $event != undefined) {
  //         record['warehouseId'] = Number($event.split('-')[0])
  //         record['warehouseName'] = $event.split('-')[1]
  //         return
  //     }
  // }
  const warehouseNameAanId: any = ref()
  const warehouseChange = () => {
    cgData.value.forEach((res: any) => {
      res['warehouseId'] = Number(warehouseNameAanId.value.split('-')[0])
      res['warehouseName'] = warehouseNameAanId.value.split('-')[1]
    })
  }

  const cadelvs = () => {
    warehouseNameAanId.value = ''
    cgData.value = []
    cgOut.visible = false
  }

  const delSles = () => {
    for (let i = 0; i < gridOption.value.getSelectedRows().length; i++) {
      if (gridOption.value.getSelectedRows()[i].infoState == 2) {
        Message.error('订单已审核通过,不可删除.')
        return
      }
    }
    Modal.confirm({
      title: '系统提示',
      content: '确认删除选中的数据?',
      onOk: () => {
        post({
          url: 'wms/ironwareInStock/delete',
          data: gridOption.value.getSelectedRows().map((res: any) => res.id),
        }).then((res: any) => {
          if (res.code == 200) {
            Message.success('删除成功')
            cxYcList()
          } else Message.error(res.message)
        })
      },
    })
  }

  const audits = () => {
    if (gridOption.value.getSelectedRows().length == 0) {
      Message.error('请勾选数据')
      return
    }
    for (let i = 0; i < gridOption.value.getSelectedRows().length; i++) {
      if (gridOption.value.getSelectedRows()[i].infoState == 2) {
        Message.error('订单已审核通过！')
        return
      }
    }
    Modal.confirm({
      title: '系统提示',
      content: '确认审核选中的数据?',
      onOk: () => {
        post({
          url: 'wms/ironwareInStock/audit',
          data: {
            infoState: 2,
            infos: gridOption.value.getSelectedRows().map((res: any) => {
              return { id: res.id }
            }),
          },
        }).then((res: any) => {
          if (res.code == 200) {
            Message.success('成功')
            cxYcList()
          } else Message.error(res.message)
        })
      },
    })
  }

  const cgData: any = ref([])
  const cgData2: any = ref([])

  const gradrList: any = ref([])

  const gradeChange = () => {
    post({
      url: 'dict/dictTypeDetail/getListByMap',
      data: {
        codeType: 36,
        detailName: '',
      },
    }).then(({ data, code }: any) => {
      if (code === 200) {
        gradrList.value = data
      }
    })
  }
  const configCascader = ref<{}>({
    corporateWidth: '200px', //公司宽度
    sectorWidth: '180px', //部门宽度
    corporateRquired: true, //公司是否必填
    sectorRquired: false, //部门是否必填
    size: 'mini', //选择框大小'mini' | 'small' | 'medium' | 'large'
    corporateName: '选择公司', //公司label
    sectorName: '选择部门', //部门label
    cascaderShow: 'sector', //配置部门不显示
  })
  const changeCascader = (data: any) => {
    const { corporateId, sectorId, sectorLabel, corporateLabel } = data
    pageData.c = corporateId
  }
  const configCascader2 = ref<{}>({
    corporateWidth: '200px', //公司宽度
    sectorWidth: '180px', //部门宽度
    corporateRquired: false, //公司是否必填
    sectorRquired: false, //部门是否必填
    size: 'mini', //选择框大小'mini' | 'small' | 'medium' | 'large'
    corporateName: '选择公司', //公司label
    sectorName: '选择部门', //部门label
    cascaderShow: 'sector', //配置部门不显示
  })
  const configCascader3 = ref<{}>({
    corporateWidth: '300px', //公司宽度
    corporateNameLabelWidth: '80px',
    sectorWidth: '180px', //部门宽度
    corporateRquired: false, //公司是否必填
    sectorRquired: false, //部门是否必填
    size: 'mini', //选择框大小'mini' | 'small' | 'medium' | 'large'
    corporateName: '选择公司', //公司label
    sectorName: '选择部门', //部门label
    cascaderShow: 'sector', //配置部门不显示
  })
  const whService = new WHService()
  const fhWhList: any = whService.whList
  const changeCascader2 = (data: any) => {
    const { corporateId, sectorId, sectorLabel, corporateLabel } = data
    pageData.b = ''
    pageData.a = corporateId
    whService.getWarhouseListByFirmId(corporateId, '五金仓')
  }
  const whService1 = new WHService()
  let fhWhList1 = ref<any>([])
  const changeCascader3 = (data: any) => {
    const { corporateId, sectorId, sectorLabel, corporateLabel } = data
    //   dataForm.id = corporateId
    fhWhList1.value = []
    dataForm.id = ''
    getWarhouseListByFirmId(corporateId, '五金仓')
  }
  const getWarhouseListByFirmId = (firmId: any, whTypeName: any) => {
    post({
      url: 'wms/warehouse/getWarehouseByPara',
      data: {
        firmId: firmId,
        warehouseTypeName: whTypeName,
        virtuallyState: 0,
      },
    }).then(({ code, data }) => {
      if (code === 200) {
        fhWhList1.value = data
      }
    })
  }
  const rejecteds = () => {
    if (tabsKeys.value == 3) {
      Modal.confirm({
        title: '系统提示',
        content: '确认驳回选中的数据?',
        onOk: () => {
          post({
            url: 'wms/ironwareOutStock/audit',
            data: {
              infoState: 1,
              infos: gridOption3.value.getSelectedRows(),
            },
          }).then((res: any) => {
            if (res.code == 200) {
              Message.success('成功')
              cxDbsList()
            } else Message.error(res.message)
          })
        },
      })
    } else if (tabsKeys.value == 4) {
      Modal.confirm({
        title: '系统提示',
        content: '确认驳回选中的数据?',
        onOk: () => {
          post({
            url: 'wms/toolOutStock/audit',
            data: {
              infoState: 1,
              infos: gridOption4.value.getSelectedRows(),
            },
          }).then((res: any) => {
            if (res.code == 200) {
              Message.success('成功')
              cxDbsList()
            } else Message.error(res.message)
          })
        },
      })
    }
  }

  const completes = () => {
    if (gridOption2.value.getSelectedRows().length == 0) {
      Message.error('请勾选数据')
      return
    }
    let isEvent = gridOption2.value
      .getSelectedRows()
      .every((v) => v.purchaseOrderNo == gridOption2.value.getSelectedRows()[0].purchaseOrderNo)
    if (!isEvent) Message.info('请选择相同采购单')
    if (!isEvent) return
    Modal.confirm({
      title: '系统提示',
      content: '确认完成选中的数据?',
      onOk: () => {
        post({
          url: 'purchase/PurchaseOrderDetail/updateByIdsInStock',
          data: gridOption2.value.getSelectedRows().map((res: any) => {
            return res.tempId
          }),
        }).then((res: any) => {
          if (res.code == 200) {
            Message.success('成功')
            cxCgsList()
          } else Message.error(res.message)
        })
      },
    })
  }

  const priceChanges = (e: any, record: any) => {
    // record.totalNum
    nextTick(() => {
      record.noTaxMoney = e * record.totalNum
    })
  }

  const onSelect = (dateString: any, date: any) => {
    pageData.dropDownTime = {
      beginTime: dateString[0],
      endTime: dateString[1],
    }
  }
  const onSelect1 = (dateString: any, date: any) => {
    pageData.dropDownTime1 = {
      beginTime: dateString[0],
      endTime: dateString[1],
    }
  }
  const onClear = () => {
    pageData.dropDownTime = []
  }
  const onClear1 = () => {
    pageData.dropDownTime1 = []
  }
  const { saveGridState: saveGridState01, updateGridState: updateGridState01 } =
    saveOrUpdateGridState01('ReceiptList2-1', gridOption, colState, tc)
  const onColumnMoved = () => {
    saveGridState01()
  }
  const onColumnResized = () => {
    saveGridState01()
  }
  const onColumnVisible = () => {
    saveGridState01()
  }
  const { saveGridState: saveGridState02, updateGridState: updateGridState02 } =
    saveOrUpdateGridState02('ReceiptList2-2', gridOption2, colState2, tc2)
  const onColumnMoved2 = () => {
    saveGridState02()
  }
  const onColumnResized2 = () => {
    saveGridState02()
  }
  const onColumnVisible2 = () => {
    saveGridState02()
  }
  const { saveGridState: saveGridState03, updateGridState: updateGridState03 } =
    saveOrUpdateGridState03('ReceiptList2-3', gridOption3, colState3, tc3)
  const onColumnMoved3 = () => {
    saveGridState03()
  }
  const onColumnResized3 = () => {
    saveGridState03()
  }
  const onColumnVisible3 = () => {
    saveGridState03()
  }
  const { saveGridState: saveGridState04, updateGridState: updateGridState04 } =
    saveOrUpdateGridState04('ReceiptList2-4', gridOption4, colState4, tc3)
  const onColumnMoved4 = () => {
    saveGridState04()
  }
  const onColumnResized4 = () => {
    saveGridState04()
  }
  const onColumnVisible4 = () => {
    saveGridState04()
  }
</script>
<script lang="ts">
  export default {
    name: 'ReceiptList2',
  }
</script>
<style scoped>
  :deep(.arco-table-td-content) {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  :deep(.arco-table .arco-table-cell) {
    padding: 9px 16px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  :deep(.arco-table-cell-align-center) {
    justify-content: center;
    text-align: center;
  }

  :deep(.arco-picker input) {
    padding-left: 0 !important;
  }

  :deep(.arco-picker) {
    padding-left: 0 !important;
  }

  :deep(.arco-picker-separator) {
    padding: 0 !important;
  }
</style>
<style>
  .arco-modal-body {
    height: 100%;
  }
</style>
